﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CRM.Admin.Contracts.Contract.Customer;
using CRM.Admin.Contracts.Model.Customer;
using KingsSharp.Common;
using KingsSharp.Core;
using KingsSharp.Core.Data;
using CRM.Admin.Contracts.Dto.Customer;

namespace CRM.Admin.Services.Service.Customer
{
    public class VarietyService : ServiceBase, IVarietyService
    {
       
         private IRepository<Variety, Guid> VarietyRepository;
        public VarietyService(IRepository<Variety, Guid> _VarietyRepository)
             : base(_VarietyRepository.UnitOfWork)
        {
            VarietyRepository = _VarietyRepository;
        }
        public IQueryable<Contracts.Model.Customer.Variety> Varietys
        {
            get { return VarietyRepository.Entities; }
        }

        public KingsSharp.Common.Data.OperationResult Insert(params Contracts.Dto.Customer.VarietyDto[] dtos)
        {
            dtos.CheckNotNull("dtos");
            foreach (var t in dtos)
            {
                t.Id = Guid.NewGuid();
            }
            var result = VarietyRepository.Insert(dtos);
            return result;
        }

        public KingsSharp.Common.Data.OperationResult Update(params Contracts.Dto.Customer.VarietyDto[] dtos)
        {
            dtos.CheckNotNull("dtos");
            var result = VarietyRepository.Update(dtos);
            return result;
        }

        public KingsSharp.Common.Data.OperationResult Delete(params Guid[] ids)
        {
            var entitys = VarietyRepository.Entities.Where(a => ids.Contains(a.Id)).ToList();
            entitys.ForEach(a => a.IsDeleted = true);
            int result = VarietyRepository.Update(entitys.ToArray());
            return new KingsSharp.Common.Data.OperationResult(KingsSharp.Common.Data.OperationResultType.Success, "删除成功");
        }
    }
}
